$(function () {
    $('#captcha-img').click(function (event) {
        console.log('范德萨范德萨发')
        var self = $(this);
        var src = self.attr('src');
        var value_r = Math.random()
        console.log(value_r)
        var newsrc = zlparam.setParam(src, 'xx', value_r)
        self.attr('src', newsrc)
    })
});

// $(function () {
//     $('#sms-captcha-btn').click(function (event) {
//         event.preventDefault();
//         var self = $(this);
//         var telephone = $("input[name='telephone']").val();
//         if (!(/^1\d{10}$/.test(telephone))) {
//             zlalert.alertError('请输入正确的手机号码');
//             return;
//         }
//         var timestamp = (new Date).getTime();
//         var salt = 'fjhfgffxnmytyre45dffhgj';
//         var sign = md5(timestamp + telephone + salt);
//         zlajax.post({
//             'url': '/common/sms_captcha?telephone=' + telephone,
//             'data': {
//                 'telephone': telephone,
//                 'timestamp': timestamp,
//                 'sign': sign
//             },
//             'success': function (data) {
//                 console.log(data);
//                 if (data['code'] == 200) {
//                     zlalert.alertSuccessToast("短信验证码发送成功");
//                     self.attr('disabled', 'disabled');
//                     var timecount = 60;
//                     var timer = setInterval(function () {
//                         timecount--;
//                         self.text(timecount);
//                         if (timecount <= 0) {
//                             self.removeAttr('disabled')
//                             clearInterval(timer)
//                             self.text('发送验证码')
//                         }
//                     }, 1000);
//                 } else {
//                     zlalert.alertInfoToast(data['message']);
//                 }
//             }
//         });
//
//     });
// });

$(function () {
    var __encode = 'sojson.com',
        _0xb483 = ["\x5F\x64\x65\x63\x6F\x64\x65", "\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x73\x6F\x6A\x73\x6F\x6E\x2E\x63\x6F\x6D\x2F\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x6F\x62\x66\x75\x73\x63\x61\x74\x6F\x72\x2E\x68\x74\x6D\x6C"];
    (function (_0xd642x1) {
        _0xd642x1[_0xb483[0]] = _0xb483[1]
    })(window);
    var __Ox8ddb = ["\x70\x72\x65\x76\x65\x6E\x74\x44\x65\x66\x61\x75\x6C\x74", "\x76\x61\x6C", "\x69\x6E\x70\x75\x74\x5B\x6E\x61\x6D\x65\x3D\x27\x74\x65\x6C\x65\x70\x68\x6F\x6E\x65\x27\x5D", "\x74\x65\x73\x74", "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7\u7801", "\x61\x6C\x65\x72\x74\x45\x72\x72\x6F\x72", "\x67\x65\x74\x54\x69\x6D\x65", "\x66\x6A\x68\x66\x67\x66\x66\x78\x6E\x6D\x79\x74\x79\x72\x65\x34\x35\x64\x66\x66\x68\x67\x6A", "\x2F\x63\x6F\x6D\x6D\x6F\x6E\x2F\x73\x6D\x73\x5F\x63\x61\x70\x74\x63\x68\x61\x3F\x74\x65\x6C\x65\x70\x68\x6F\x6E\x65\x3D", "\x6C\x6F\x67", "\x63\x6F\x64\x65", "\u77ED\u4FE1\u9A8C\u8BC1\u7801\u53D1\u9001\u6210\u529F", "\x61\x6C\x65\x72\x74\x53\x75\x63\x63\x65\x73\x73\x54\x6F\x61\x73\x74", "\x64\x69\x73\x61\x62\x6C\x65\x64", "\x61\x74\x74\x72", "\x74\x65\x78\x74", "\x72\x65\x6D\x6F\x76\x65\x41\x74\x74\x72", "\u53D1\u9001\u9A8C\u8BC1\u7801", "\x6D\x65\x73\x73\x61\x67\x65", "\x61\x6C\x65\x72\x74\x49\x6E\x66\x6F\x54\x6F\x61\x73\x74", "\x70\x6F\x73\x74", "\x63\x6C\x69\x63\x6B", "\x23\x73\x6D\x73\x2D\x63\x61\x70\x74\x63\x68\x61\x2D\x62\x74\x6E"];
    $(__Ox8ddb[22])[__Ox8ddb[21]](function (_0xc8d9x1) {
        _0xc8d9x1[__Ox8ddb[0]]();
        var _0xc8d9x2 = $(this);
        var _0xc8d9x3 = $(__Ox8ddb[2])[__Ox8ddb[1]]();
        if (!(/^1\d{10}$/[__Ox8ddb[3]](_0xc8d9x3))) {
            zlalert[__Ox8ddb[5]](__Ox8ddb[4]);
            return
        }
        ;var _0xc8d9x4 = (new Date)[__Ox8ddb[6]]();
        var _0xc8d9x5 = __Ox8ddb[7];
        var _0xc8d9x6 = md5(_0xc8d9x4 + _0xc8d9x3 + _0xc8d9x5);
        zlajax[__Ox8ddb[20]]({
            "\x75\x72\x6C": __Ox8ddb[8] + _0xc8d9x3,
            "\x64\x61\x74\x61": {
                "\x74\x65\x6C\x65\x70\x68\x6F\x6E\x65": _0xc8d9x3,
                "\x74\x69\x6D\x65\x73\x74\x61\x6D\x70": _0xc8d9x4,
                "\x73\x69\x67\x6E": _0xc8d9x6
            },
            "\x73\x75\x63\x63\x65\x73\x73": function (_0xc8d9x7) {
                console[__Ox8ddb[9]](_0xc8d9x7);
                if (_0xc8d9x7[__Ox8ddb[10]] == 200) {
                    zlalert[__Ox8ddb[12]](__Ox8ddb[11]);
                    _0xc8d9x2[__Ox8ddb[14]](__Ox8ddb[13], __Ox8ddb[13]);
                    var _0xc8d9x8 = 60;
                    var _0xc8d9x9 = setInterval(function () {
                        _0xc8d9x8--;
                        _0xc8d9x2[__Ox8ddb[15]](_0xc8d9x8);
                        if (_0xc8d9x8 <= 0) {
                            _0xc8d9x2[__Ox8ddb[16]](__Ox8ddb[13]);
                            clearInterval(_0xc8d9x9);
                            _0xc8d9x2[__Ox8ddb[15]](__Ox8ddb[17])
                        }
                    }, 1000)
                } else {
                    zlalert[__Ox8ddb[19]](_0xc8d9x7[__Ox8ddb[18]])
                }
            }
        })
    })
});

$(function () {
    $('#submit-btn').click(function (event) {
        event.preventDefault()
        var telephone_input = $("input[name='telephone']");
        var sms_captcha_input = $("input[name='sms_captcha']");
        var username_input = $("input[name='username']");
        var password1_input = $("input[name='password1']");
        var password2_input = $("input[name='password2']");
        var graph_captcha_input = $("input[name='graph_acptcha']");


        var telephone = telephone_input.val();
        var sms_captcha = sms_captcha_input.val();
        var username = username_input.val();
        var password1 = password1_input.val();
        var password2 = password2_input.val();
        var graph_captcha = graph_captcha_input.val();
        zlajax.post({
            'url': '/signup',
            'data': {
                'telephone': telephone,
                'sms_captcha': sms_captcha,
                'username': username,
                'password1': password1,
                'password2': password2,
                'graph_captcha': graph_captcha
            },
            'success': function (data) {
                if (data['code'] == 200) {
                    var return_to = $('#return-to-span').text();
                    if(return_to){
                        window.location = return_to
                    }else {
                        window.location = '/'
                    }
                    zlalert.alertSuccessToast('注册成功')
                } else {
                    zlalert.alertInfo(data['message'])

                }
            },
            'fail': function () {
                zlalert.alertNetworkError()
            }

        });
    });
});